<?php

namespace app\index\controller;

use app\common\common\Helper;
use app\index\service\DeviceService;
use app\common\model\oms\Companies as CompanyModel;
use think\Cache;

/**
 * Description of Device
 *
 * @author tommy.pan
 */
class Device extends \app\common\controller\AuthBase {

    /**
     * 显示集团及门店设备接口
     */
    public function getCompanyOptometryDevice() {
        $params = $this->input();
        $param_list = [
            'company_code' => 'string',
            'store_id'     => 'string',
        ];
        $this->diffParam($param_list, $params);
        $deviceService = new DeviceService();
        $data = $deviceService->getCompanyOptometryDeviceArray($params);
        if (false === empty($data)) {
            return $this->output($data);
        }
        return $this->output([], '获取公司设备失败', 200);
    }

    /**
     * 修改门店设备状态
     */
    public function editStoreOptometryDeviceStatus() {
        $params = $this->input();
        $param_list = [
            'company_code' => 'string', //集团标识
            'store_id'     => 'string', //门店ID
            'action'       => 'int', //1使用，0关闭
        ];
        $this->diffParam($param_list, $params);
        $deviceService = new DeviceService();
        $companyModel = new CompanyModel();
        $companyInfo = $companyModel->getCompanyInfoByCondition('company_id', ['company_Code' => $params['company_code']], true);
        $params['company_id'] = $companyInfo['company_id'];
        $data = $deviceService->editStoreOptometryDeviceStatus($params);
        if (false === empty($data)) {
            $data['sod_id'] = $data['id']; //如果是新增则返回sod_id
            return $this->output($data);
        }
        return $this->output([], '添加或者删除设备失败', 200);
    }

}
